function addMidMarker(location) {
  var infowindow;
  var marker = new google.maps.Marker({
    	animation: google.maps.Animation.DROP,
    	position: location,
    	map: map
  });
  var infowindow = new google.maps.InfoWindow({
	content: "Middle location"
  });
  google.maps.event.addListener(marker, 'click', function() {
	infowindow.open(map,marker);
  });
  markersArray.push(marker);
}

function addLocMarker(id, name, lat, lng) {
  console.log("called addLocMarker.......");
  var exists = new Boolean(false);
  if (name != usrname) {
    var loc = new google.maps.LatLng(lat,lng);
    //var exists = new Boolean(false);
    var marker = new google.maps.Marker({
      position: loc,
      map: map
    });
	var infowindow = new google.maps.InfoWindow({
		content: "Location of " + name
	  });
	  google.maps.event.addListener(marker, 'click', function() {
		infowindow.open(map,marker);
	  });
    if (name == "root") {
      marker.setPosition(stanford);
      geoloc = stanford;
    }
	if (name == "bear") {
		var berkely = new google.maps.LatLng(37.8716667,-122.2716667);
		marker.setPosition(berkely);
		geoloc = berkely;
	}
    var mem = new memberInfo(id, name, marker);
    console.log("mem id = " + mem.id);
    for (existingMem in locArray) {
  	  if (mem.id == locArray[existingMem].id) {
  	    mem.marker.setMap(null);
        mem = null;
        exists = true;
        break;
  	  }
    }
    if (exists == false) {
      console.log("location array pushed to!!");
      locArray.push(mem);
    }
  } 
  if (usrname == "-1") {
  	usrname = name;
  }
}

function addPlaceMarker(lat, lng, info) {
	var loc = new google.maps.LatLng(lat,lng);
    var marker = new google.maps.Marker({
		animation: google.maps.Animation.DROP,
      	position: loc,
      	map: map
    });
	var infowindow = new google.maps.InfoWindow({
		content: info
	});
	google.maps.event.addListener(marker, 'click', function() {
		infowindow.open(map,marker);
	});
    markersArray.push(marker);
}

// Removes the overlays from the map, but keeps them in the array
function clearOverlays() {
  if (markersArray) {
    for (i in markersArray) {
      markersArray[i].setMap(null);
    }
  }
}

// Shows any overlays currently in the array
function showOverlays() {
  if (markersArray) {
    for (i in markersArray) {
      markersArray[i].setMap(map);
    }
  }
}

// Deletes all markers in the array by removing references to them
function deleteOverlays() {
  if (markersArray) {
    for (i in markersArray) {
      markersArray[i].setMap(null);
    }
    markersArray.length = 0;
  }
}

function getNumPeopleOnMap() {
	return markersArray.length;
}

function getCurrentLat() {
	if (geoloc) {
		return geoloc.lat();
	}
	return null;
}

function getCurrentLng() {
	if (geoloc) {
		return geoloc.lng();
	}
	return null;
}